package com.adtech.adms.system.service.impl;

import java.util.List;

import com.adtech.adms.system.SystemConstants;
import com.adtech.adms.system.pojo.SysAdminLog;
import com.adtech.adms.system.pojo.User;
import com.adtech.adms.system.service.SystemLogService;
import com.adtech.core.cache.Cache;
import com.adtech.core.dao.HibernateDAO;
import com.adtech.core.dao.exp.Expression;
import com.adtech.core.dao.query.Pager;
import com.adtech.core.dao.query.QueryConstants;
import com.adtech.core.dao.query.Sort;

public class SystemLogServiceImpl implements SystemLogService{
	private HibernateDAO dao;
	private Cache templateCache;
	public Cache getTemplateCache() {
		return templateCache;
	}

	public void setTemplateCache(Cache templateCache) {
		this.templateCache = templateCache;
	}
	@Override
	public List<SysAdminLog> getLogList(Pager pager, Expression expression,
			Sort sort) {
		if(sort==null || sort.isEmpty()) {
			sort = new Sort();
			sort.addSort(SystemConstants.SystemLog.LOG_DATE, QueryConstants.DESC);
		}
		//expression = Condition.and(Condition.eq(SystemConstants.User.IS_DELETE, "0"), expression);
		return (List<SysAdminLog>)dao.getByQuery(SysAdminLog.class, pager, expression, sort);
	}
	public void setDao(HibernateDAO dao) {
		this.dao = dao;
	}

	@Override
	public void delete(String id, User currentUser) {
		if (id == null || id.length() == 0) {
			return;
		}
		String[] ids = id.split(",");
		for(String syslogId : ids) {
			if(syslogId!=null && syslogId.length()>0) {
				SysAdminLog systemLog = dao.getById(SysAdminLog.class, Integer.parseInt(syslogId));
				dao.delete(systemLog);
			}
		}
		dao.flushSession();
		
	}

}
